home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 9,300 to 9,399 / 9300.zip / AOLDLs / HTML & Web Tools (MAC) / WEB_ Print2Pict 3.7.1 / Print2Pict 3.7.1Ä.sit / Print2Pict 3.7.1ƒ / Sourcesƒ / P2PX.h < prev    next >
C/C++ Source or Header  |  2005-06-15  |  16KB  |  428 lines

  1. #pragma once        // new method of ensuring file is included only once
  2. #define _H_P2PX        // old method
  3.  
  4. //    
  5. //    File P2PX.h
  6. //    ⌐ B.Raoult 1992
  7. //    
  8. //    baudouin.raoult@ecmwf.int
  9. //    
  10. //    How to write a Print2Pict extension:
  11. //    ------------------------------------
  12. //    
  13. //    A Print2Pict extension is a code resource of type 'P2PX' id = -8192, in
  14. //    a file of type 'P2PX' and creator 'P2P '. The code entry point is a
  15. //    Pascal function (so extension can be wrote in Pascal or C).
  16. //    
  17. //        pascal OSErr main (short msg, P2PXPtr arg);
  18. //    
  19. //    The function is called with two parameters: the first is a function
  20. //    selector, the second is a pointer to a parameter block containing
  21. //    various field described later. The function must return noErr if
  22. //    everything was OK, or the code of any errors.
  23. //    
  24. //    When the extension is called, the current resource file is set to the
  25. //    extension file.
  26. //
  27. // You can write a 'fat' extension by adding a 'P2Px' id = -8192 to the
  28. // resource file
  29. //    
  30. //    Values of the message parameter:
  31. //    ================================
  32. //    
  33. //    - kGetFlagsMsg
  34. //    -------------
  35. //    
  36. //    This message is sent before opening the Style or the Job dialogs:
  37. //    Print2Pict use the answer to enable or disable some items in the
  38. //    dialogs. You must fill the "flags" with the following values:
  39. //    
  40. //    if  kEnvironmentOk is not set, the name of the extension is disabled in
  41. //    the popup menu. It cannot be selected by the user. You must clear this
  42. //    bit if your extension requires system features that are not available
  43. //    on this machine. (Color QuickDraw, ...)
  44. //    
  45. //    if kWantFileNames is set, Print2Pict will generate a filename for
  46. //    every page printed and pass it to you in the "fsspec" and "script"
  47. //    fields of the argument when sending the kPutPageMsg message. This name
  48. //    either automatically generated or was specified by the user according
  49. //    to the user choice in the Print2Pict options dialog. Use the "creator"
  50. //    field to create the files. If you want only one file name, clear the
  51. //    kWantFileNames bit once you have received the first kPutPageMsg
  52. //    message.
  53. //    
  54. //    if kHasOwnPageSize is set, Print2Pict will look for a PREC resource
  55. //    id = 3 in your resource file to setup the Style dialog. A maximum of 5
  56. //    page sizes can be displayed (the sixth is reserved for the custom paper
  57. //    size). When this bit is set, the external cannot be selected in the Job
  58. //    dialog, as an other size may have been chosen in the Style dialog.
  59. //    
  60. //    if kHasOwnOptions is set, your external must provide a DITL resource
  61. //    id = -8192, and ICON resource id = -8192 and optionally a cicn resource
  62. //    id = -8192. The ICON (or cicn) is displayed in the options dialog. If
  63. //    the user click on it, the DITL is then appended to the dialog. Your
  64. //    external must respond to the kOptOpenMsg, kOptEventMsg, kOptItemMsg and
  65. //    kOptDoneMsg messages.
  66. //    
  67. //    if kOnlyBlackAndWhite is set, Print2Pict will create black and white
  68. //    picture.
  69. //    
  70. //    if kCanPreview is set the user can preview the pages before they are
  71. //    disposed. If you provide a resource PREV id = -8192 containing a pascal
  72. //    string that will be use to change the title of the disposition button
  73. //    in the preview dialog.
  74. //    
  75. //    if kCanSpool is set, Print2Pict may spool the picture to a file if the
  76. //    memory is too low. The spooled field is set, spooledfile contains the
  77. //    filespec of the spooled picture (PICT format). [NOT YET IMPLEMENTED]
  78. //    
  79. //    if kNeedLock is set, the extension is locked before the 'kInitMsg' and 
  80. //    'kOptOpenMsg' and released after the 'kEndMsg' and the 'kOptDoneMsg'. This
  81. //    is if you want to install some patches, system callbacks (like dialog items
  82. //    drawing routines),... But when these routines callbacks are called, the 
  83. //    current resource file may not be yours, so save it somewhere. [FROM VERSION 3.6 ONLY]
  84. //
  85. //    When entering your routine the "flags" field is set with the
  86. //    kDefaultFlags values (kEnvironmentOk + kWantFileNames + kCanPreview).
  87. //    
  88. //    The kGetFlagsMsg message is also sent when the application calls
  89. //    PrOpenDoc, before sending the kInitMsg, to check if the kEnvironmentOk
  90. //    is still set.
  91. //    
  92. //    Don't use any fields of the argument other than the "flags" field.
  93. //    
  94. //    - kInitMsg
  95. //    ---------
  96. //    
  97. //    The message is sent when the application calls PrOpenDoc. If you need
  98. //    some local storage, allocate a handle, and put it in the "data" field
  99. //    of the argument.
  100. //    
  101. //    - kEndMsg
  102. //    --------
  103. //    
  104. //    The message is sent when the application calls PrCloseDoc. You must free
  105. //    any memory allocated, close any opened file.
  106. //    
  107. //    Always check the "data" field before calling DisposHandle.
  108. //    
  109. //    - kPutPageMsg
  110. //    ------------
  111. //    
  112. //    The message is sent when the application calls PrClosePage. This is
  113. //    where you must process the picture.
  114. //    
  115. //            "error"        is the last error.
  116. //            "page"      contains the current page number. (Starting from 1)
  117. //            "pict"      contains a handle on the picture of the current page.
  118. //            "docName"   is the name of the printed document (can be empty).
  119. //            "appName"   is the name of the current application.
  120. //    
  121. //    If kWantFileNames is set in the "flags" field: "fsspec"  is the file
  122. //    spec where the page is to be saved, and "script"  the scriptcode to use
  123. //    with FSpCreate.
  124. //    
  125. //    If kCanSpool is set in the "flags" field, Print2Pict may spool the
  126. //    picture to disk if the memory is low. [NOT YET IMPLEMENTED] "pict" is
  127. //    the set to NULL, "spooled" is true, and "spoolfile" contains the file
  128. //    spec of the file where the picture is spooled (PICT format)
  129. //    
  130. //    - kNewPageMsg ( added with version 3.4 of Print2Pict )
  131. //    ------------
  132. //    
  133. //    The message is sent when the application calls PrOpenPage. The current
  134. //    port is the printing port and OpenPicture has been called.
  135. //    
  136. //            "error"        is the last error.
  137. //            "page"      contains the current page number. (Starting from 1)
  138. //            "docName"   is the name of the printed document (can be empty).
  139. //            "appName"   is the name of the current application.
  140. //    
  141. //    
  142. //    - kOptOpenMsg
  143. //    ------------
  144. //    
  145. //    To receive this message the kHasOwnOptions bit must be set. Print2Pict
  146. //    display the DITL you provide and calls the external. You can allocate
  147. //    some private storage in the "data" field. You must initialize the
  148. //    dialog items here. "dlog" is the dialog containing your items, "skip"
  149. //    is the number of items in this dialog belonging to Print2Pict.
  150. //    
  151. //             IMPORTANT NOTE: Before version 3.6, there was a bug that prevented
  152. //            PICT, ICON and CNTL items in the dialogs. This bug is fixed. 
  153. //
  154. //    - kOptEventMsg
  155. //    -------------
  156. //    
  157. //    To receive this message the kHasOwnOptions bit must be set. The
  158. //    external is called from the ModalDialog filter procedure.
  159. //    
  160. //    "dlog" is the dialog containing your items, "skip" is the number of
  161. //    items in this dialog belonging to Print2Pict. "event" is the events
  162. //    that triggered the call, "itemHit" is the item passed to the filter
  163. //    procedure, "retcode" must be set to true if "itemHit" was changed. See
  164. //    InsideMac I page 415 for more details about the filter procedure.
  165. //    
  166. //    - kOptItemMsg
  167. //    ------------
  168. //    
  169. //    To receive this message the kHasOwnOptions bit must be set. The
  170. //    external is called with the item returned by ModalDialog. You must
  171. //    update the check boxes and the radio buttons. "item" is the value
  172. //    return by ModalDialog. "dlog" is the dialog containing your items,
  173. //    "skip" is the number of items in this dialog belonging to Print2Pict.
  174. //    The dialog item "skip" is a static text you can use to display any
  175. //    messages.
  176. //    
  177. //    - kOptDoneMsg
  178. //    ------------
  179. //    
  180. //    To receive this message the kHasOwnOptions bit must be set. Print2Pict
  181. //    calls the external before removing the DITL from the dialog. You must
  182. //    get the new values of the dialog items, and release any allocated
  183. //    memory. "dlog" is the dialog containing your items, "skip" is the
  184. //    number of items in this dialog belonging to Print2Pict.
  185. //    
  186. //    Values of the P2PXPtr parameter:
  187. //    ================================
  188. //    
  189. //    For every calls, a parameter is passed to the extension. All field are
  190. //    read only except "flags" and "data".
  191. //    
  192. //    Print2Pict fills the block with zeros and then sets the fields. So you
  193. //    are sure that missing fields are set to zero:
  194. //    
  195. //    ALWAYS CHECK A POINTER (OR HANDLE) FIELD AGAINST NULL BEFORE
  196. //    DEREFERENCING IT.
  197. //    
  198. //    This is a description of the field of the parameter block using the
  199. //    format - name (type) [list of messages for which the field is valid]
  200. //    
  201. //    - vers (short) [all]
  202. //    --------------------
  203. //    
  204. //    Print2Pict version, the low byte contains the major version (3 at
  205. //    present). The high byte containt the minor version (4 now). They are
  206. //    swapped for compatibility with version 3.0. Use the P2PVERSION macro
  207. //    to get the version in BCD (i.e vers 3.5 is 0x305)
  208. //    
  209. //    - port (TPPrPort) [kPutPageMsg,kNewPageMsg]
  210. //    -----------------------------------------
  211. //    
  212. //        Current print graph port.
  213. //    
  214. //    - hPrint (THPrint) [kPutPageMsg,kNewPageMsg]
  215. //    ------------------------------------------
  216. //    
  217. //        Current print record.
  218. //    
  219. //    - page (short) [kPutPageMsg,kNewPageMsg]
  220. //    --------------------------------------
  221. //    
  222. //        Current page number (starting from 1).
  223. //    
  224. //    - pict (PicHandle) [kPutPageMsg]
  225. //    -------------------------------
  226. //    
  227. //        Picture of the current page. If NULL, then the picture was spooled (see
  228. //        spooled and spoolfile)
  229. //    
  230. //    - color (Boolean) [kPutPageMsg,kNewPageMsg]
  231. //    -----------------------------------------
  232. //    
  233. //        Set to true if the print grafport is the color port.
  234. //    
  235. //    - flags (long) [all]
  236. //    --------------------
  237. //    
  238. //        Set by the extension. See previous paragraph.
  239. //    
  240. //    - error (OSErr) [all]
  241. //    --------------------
  242. //    
  243. //        Last error reported by Print2Pict.
  244. //    
  245. //    - data (Handle) [kInitMsg,kPutPageMsg,kEndMsg,kNewPageMsg]
  246. //                    [kOptOpenMsg,kOptEventMsg,kOptItemMsg,kOptDoneMsg if kHasOwnOptions]
  247. //    ---------------------------------------------------------------------------------
  248. //    
  249. //        Put here a handle to your private storage. Alocate it when
  250. //        you receive kInitMsg or kOptOpenMsg, free it when you receive kEndMsg or kOptDoneMsg.
  251. //    
  252. //    - docName (Str255) [kInitMsg,kPutPageMsg,kEndMsg,kNewPageMsg]
  253. //    ---------------------------------------------------------
  254. //    
  255. //        Name of the printed document.
  256. //    
  257. //    - appName (Str255) [kInitMsg,kPutPageMsg,kEndMsg,kNewPageMsg]
  258. //    ---------------------------------------------------------
  259. //    
  260. //        Name of the current application.
  261. //    
  262. //    - fspec (FSSpec) [kPutPageMsg if kWantFileNames]
  263. //    ------------------------------------------------
  264. //    
  265. //        File spec. where to save the picture to.
  266. //    
  267. //    - script (ScriptCode) [kPutPageMsg if kWantFileNames]
  268. //    -----------------------------------------------------
  269. //    
  270. //        script code of fspec (needed for FSpCreate).
  271. //    
  272. //    - creator (OSType) [all]
  273. //    ------------------------
  274. //    
  275. //        creator choosen by the user in the Print2Pict options dialog.
  276. //    
  277. //    - spooled (Boolean) [kPutPageMsg if kCanSpool] [NOT YET IMPLEMENTED]
  278. //    -------------------------------------------------------------------
  279. //    
  280. //        true if the picture was spooled.
  281. //    
  282. //    - spoolfile (FSSpec) [kPutPageMsg if kCanSpool] [NOT YET IMPLEMENTED]
  283. //    --------------------------------------------------------------------
  284. //    
  285. //        file spec of the spooled picture (PICT file). set if spooled is true.
  286. //    
  287. //    - dlog  (DialogPtr) [kOptOpenMsg,kOptEventMsg,kOptItemMsg,kOptDoneMsg if kHasOwnOptions]
  288. //    -------------------------------------------------------------------------------------
  289. //    
  290. //        Dialog where the your DITL is displayed.
  291. //    
  292. //    - event (EventRecord*) [kOptEventMsg if kHasOwnOptions]
  293. //    -------------------------------------------------------
  294. //    
  295. //        Event received in ModalDialog filter procedure.
  296. //    
  297. //    - itemHit (short*) [kOptEventMsg if kHasOwnOptions]
  298. //    ---------------------------------------------------
  299. //    
  300. //        Item received in ModalDialog filter procedure.
  301. //    
  302. //    - retcode (Boolean) [kOptEventMsg if kHasOwnOptions]
  303. //    ----------------------------------------------------
  304. //    
  305. //        Return code of ModalDialog filter procedure.
  306. //    
  307. //    - skip (short) [kOptOpenMsg,kOptEventMsg,kOptItemMsg,kOptDoneMsg if kHasOwnOptions]
  308. //    --------------------------------------------------------------------------------
  309. //    
  310. //        Number of items belonging to Print2Pict in the dialog.
  311. //    
  312. //    - item (short) [kOptItemMsg if kHasOwnOptions]
  313. //    ----------------------------------------------
  314. //    
  315. //        Item number returned by ModalDialog.
  316. //    
  317. //    Help:
  318. //    =====
  319. //    
  320. //    To provide somme help to the user, add a TEXT resource id = -8192 and an
  321. //    optional styl resource, same id. The text will be displayed in the Help
  322. //    window.
  323. //        
  324. //    Ideas:
  325. //    ======
  326. //    
  327. //    Here are some ideas of extensions:
  328. //    
  329. //        - Print to Movie (QuickTime) each page is a frame.
  330. //        - HyperPrint (HyperCard) each page is a card. Has its own paper format (the
  331. //          size of a card.
  332. //        - Print to RTF, Print to Word, ... all text formats.
  333. //        - Print to PCX, GIF, all PC stuff, ....
  334. //        - Print to X, XWindows Pixmaps.
  335. //        
  336. //        You are welcome to send me any extensions you write, so I can add them to
  337. //        the next releases of Print2Pict.
  338. //
  339.  
  340. #ifndef __PRINTING__
  341. #    include <Printing.h>
  342. #endif
  343.  
  344. #ifndef __FILES__
  345. #    include <Files.h>
  346. #endif
  347.  
  348. //============================ Messages =====================================
  349.  
  350. enum {
  351.     kNoMsg,
  352.     kGetFlagsMsg,
  353.     kInitMsg,
  354.     kEndMsg,
  355.     kPutPageMsg,
  356.     kOptOpenMsg,
  357.     kOptEventMsg,
  358.     kOptItemMsg,
  359.     kOptDoneMsg,
  360.     kNewPageMsg
  361. };
  362.  
  363. //=============================== Flags =====================================
  364.  
  365. enum {
  366.     kEnvironmentOk        = 1 << 0, // Set if machine OK (i.e. has color QD,...)
  367.     kWantFileNames        = 1 << 1, // If code resource need file names
  368.     kHasOwnPageSize        = 1 << 2, // If the code has its own page size
  369.     kCanPreview            = 1 << 3, // Pages can be previewed before disposed
  370.     kHasOwnOptions        = 1 << 4, // If code has own options dialog
  371.     kOnlyBlackAndWhite    = 1 << 5, // No color pictures
  372.     kCanSpool            = 1 << 6, // Can use spooled pictures
  373.     kNeedLock            = 1 << 7  // The extension is locked between calls, new in version 3.6
  374. };
  375.  
  376. #define kDefaultFlags       (kEnvironmentOk+kWantFileNames+kCanPreview)
  377.  
  378. #define P2PVERSION(arg)        ((arg->vers >> 8) + ((arg->vers & 0xf) << 8))
  379.  
  380. //============================= Parameter block =============================
  381.  
  382. typedef struct
  383. {
  384.     short       vers;       // Print2Pict major version (3 now)
  385.     TPPrPort    port;       // Print graphport
  386.     THPrint     hPrint;     // Print record
  387.     short       page;       // Current page
  388.     PicHandle   pict;       // Content of page
  389.     Boolean     color;      // The printport is a color port
  390.     long        flags;      // Code flags
  391.     Handle      data;       // Free to use
  392.     OSErr        error;        // Last error code
  393.     Str255      docName;    // Name of printed document
  394.     Str255      appName;    // Name of current application
  395.     FSSpec      fspec;      // File spec if kWantFileNames
  396.     ScriptCode  script;     // Script code if kWantFileNames
  397.     OSType      creator;    // user chosen creator
  398.     Boolean     spooled;    // Picture was spooled
  399.     FSSpec      spoolfile;  // Spolled picture
  400.  
  401.     // for options dialog
  402.  
  403.     DialogPtr   dlog;       // The options dialog
  404.     EventRecord *event;     // Event received in ModalDialog filter proc
  405.     short       *itemHit;   // Item received in ModalDialog filter proc
  406.     Boolean     retcode;    // Retcode of ModalDialog filter proc
  407.     short       skip;       // Number of items belonging to Print2Pict
  408.     short       item;       // Item number returned by modal dialog
  409. }
  410. P2PXRec, *P2PXPtr;
  411.  
  412. //============================= UUP For fat resource =============================
  413. enum {
  414.     uppP2PXEntryProcInfo = kPascalStackBased
  415.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  416.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(short)))
  417.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(P2PXPtr)))
  418. };
  419.  
  420. #ifndef BuildingP2P
  421. #ifdef powerc
  422. pascal  OSErr main(short msg,P2PXPtr arg);
  423.  
  424. // Don't change this name
  425. RoutineDescriptor    P2PX = BUILD_ROUTINE_DESCRIPTOR(uppP2PXEntryProcInfo, main);
  426. #endif
  427. #endif
  428.